import { defHttp } from "/@/utils/http/axios"
import { Modal } from "ant-design-vue"
import { Api } from "/@/api/url"

export const getArticle = (params) => {
  return defHttp.get({ url: Api.getArticle, params })
}

export const pageArticle = (params) => {
  return defHttp.get({ url: Api.pageArticle, params })
}

export const saveOrUpdateArticle = (params, isUpdate) => {
  const url = isUpdate ? Api.updateArticle : Api.saveArticle
  return defHttp.post({ url: url, params })
}

export const deleteArticle = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteArticle, data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

export const batchDeleteArticle = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: Api.batchDeleteArticle, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}

export const listGroup = (params) => {
  return defHttp.get({ url: Api.listArticleGroup, params })
}

export const saveOrUpdateGroup = (params, isUpdate) => {
  const url = isUpdate ? Api.updateArticleGroup : Api.saveArticleGroup
  return defHttp.post({ url: url, params })
}

export const deleteGroup = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteArticleGroup, data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

export const batchDeleteGroup = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: Api.batchDeleteArticleGroup, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}
